<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li class="active"><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01.UmiJS">1.UmiJS</a></li><li><a href="#t12.安装">2.安装</a><ul><li><a href="#t22.1 目录约定">2.1 目录约定</a></li><li><a href="#t32.2 mock">2.2 mock</a></li></ul></li><li><a href="#t43. 启动项目">3. 启动项目</a></li><li><a href="#t54. layouts">4. layouts</a><ul><li><a href="#t64.1 layouts/index.js">4.1 layouts/index.js</a></li></ul></li><li><a href="#t75. 用户管理">5. 用户管理</a><ul><li><a href="#t85.1 user/_layout.js">5.1 user/_layout.js</a></li><li><a href="#t95.2 user/list.js">5.2 user/list.js</a></li><li><a href="#t105.3 pages/user/add.js">5.3 pages/user/add.js</a></li><li><a href="#t115.3 detail/$id.js">5.3 detail/$id.js</a></li></ul></li><li><a href="#t126. 权限路由">6. 权限路由</a><ul><li><a href="#t136.1  profile.js">6.1  profile.js</a></li><li><a href="#t146.2 routes/PrivateRoute.js">6.2 routes/PrivateRoute.js</a></li></ul></li><li><a href="#t157. react动画">7. react动画</a><ul><li><a href="#t167.1 src/pages/user/_layout.js">7.1 src/pages/user/_layout.js</a></li></ul></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01.UmiJS">1.UmiJS <a href="#t01.UmiJS"> # </a></h2>
<ul>
<li><a href="https://umijs.org/zh/guide/">UmiJS</a> &#x662F;&#x4E00;&#x4E2A;&#x7C7B; Next.JS &#x7684; react &#x5F00;&#x53D1;&#x6846;&#x67B6;&#x3002;</li>
<li>&#x4ED6;&#x57FA;&#x4E8E;&#x4E00;&#x4E2A;&#x7EA6;&#x5B9A;&#xFF0C;&#x5373; pages &#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6587;&#x4EF6;&#x5373;&#x8DEF;&#x7531;&#xFF0C;&#x800C;&#x6587;&#x4EF6;&#x5219;&#x5BFC;&#x51FA; react &#x7EC4;&#x4EF6;</li>
<li>&#x7136;&#x540E;&#x6253;&#x901A;&#x4ECE;&#x6E90;&#x7801;&#x5230;&#x4EA7;&#x7269;&#x7684;&#x6BCF;&#x4E2A;&#x9636;&#x6BB5;&#xFF0C;&#x5E76;&#x914D;&#x4EE5;&#x5B8C;&#x5584;&#x7684;&#x63D2;&#x4EF6;&#x4F53;&#x7CFB;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x80FD;&#x628A; umi &#x7684;&#x4EA7;&#x7269;&#x90E8;&#x7F72;&#x5230;&#x5404;&#x79CD;&#x573A;&#x666F;&#x91CC;&#x3002;</li>
</ul>
<p><img src="https://camo.githubusercontent.com/6814f490328a0f65734a4913525987a959fd6253/68747470733a2f2f7368697075736572636f6e74656e742e636f6d2f33616138333237306131363061333263313434366263346134323366613330332f506173746564253230496d616765253230322e706e67" alt="umiJS"></p>
<h2 id="t12.&#x5B89;&#x88C5;">2.&#x5B89;&#x88C5; <a href="#t12.&#x5B89;&#x88C5;"> # </a></h2>
<pre><code class="lang-js">npm install -g umi
</code></pre>
<h3 id="t22.1 &#x76EE;&#x5F55;&#x7EA6;&#x5B9A;">2.1 &#x76EE;&#x5F55;&#x7EA6;&#x5B9A; <a href="#t22.1 &#x76EE;&#x5F55;&#x7EA6;&#x5B9A;"> # </a></h3>
<pre><code class="lang-js">.
&#x251C;&#x2500;&#x2500; dist/                          <span class="hljs-comment">// &#x9ED8;&#x8BA4;&#x7684; build &#x8F93;&#x51FA;&#x76EE;&#x5F55;</span>
&#x251C;&#x2500;&#x2500; mock/                          <span class="hljs-comment">// mock &#x6587;&#x4EF6;&#x6240;&#x5728;&#x76EE;&#x5F55;&#xFF0C;&#x57FA;&#x4E8E; express</span>
&#x251C;&#x2500;&#x2500; config/
    &#x251C;&#x2500;&#x2500; config.js                  <span class="hljs-comment">// umi &#x914D;&#x7F6E;&#xFF0C;&#x540C; .umirc.js&#xFF0C;&#x4E8C;&#x9009;&#x4E00;</span>
&#x2514;&#x2500;&#x2500; src/                           <span class="hljs-comment">// &#x6E90;&#x7801;&#x76EE;&#x5F55;&#xFF0C;&#x53EF;&#x9009;</span>
    &#x251C;&#x2500;&#x2500; layouts/index.js           <span class="hljs-comment">// &#x5168;&#x5C40;&#x5E03;&#x5C40;</span>
    &#x251C;&#x2500;&#x2500; pages/                     <span class="hljs-comment">// &#x9875;&#x9762;&#x76EE;&#x5F55;&#xFF0C;&#x91CC;&#x9762;&#x7684;&#x6587;&#x4EF6;&#x5373;&#x8DEF;&#x7531;</span>
        &#x251C;&#x2500;&#x2500; .umi/                  <span class="hljs-comment">// dev &#x4E34;&#x65F6;&#x76EE;&#x5F55;&#xFF0C;&#x9700;&#x6DFB;&#x52A0;&#x5230; .gitignore</span>
        &#x251C;&#x2500;&#x2500; .umi-production/       <span class="hljs-comment">// build &#x4E34;&#x65F6;&#x76EE;&#x5F55;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x5220;&#x9664;</span>
        &#x251C;&#x2500;&#x2500; <span class="hljs-built_in">document</span>.ejs           <span class="hljs-comment">// HTML &#x6A21;&#x677F;</span>
        &#x251C;&#x2500;&#x2500; <span class="hljs-number">404.</span>js                 <span class="hljs-comment">// 404 &#x9875;&#x9762;</span>
        &#x251C;&#x2500;&#x2500; page1.js               <span class="hljs-comment">// &#x9875;&#x9762; 1&#xFF0C;&#x4EFB;&#x610F;&#x547D;&#x540D;&#xFF0C;&#x5BFC;&#x51FA; react &#x7EC4;&#x4EF6;</span>
        &#x251C;&#x2500;&#x2500; page1.test.js          <span class="hljs-comment">// &#x7528;&#x4F8B;&#x6587;&#x4EF6;&#xFF0C;umi test &#x4F1A;&#x5339;&#x914D;&#x6240;&#x6709; .test.js &#x548C; .e2e.js &#x7ED3;&#x5C3E;&#x7684;&#x6587;&#x4EF6;</span>
        &#x2514;&#x2500;&#x2500; page2.js               <span class="hljs-comment">// &#x9875;&#x9762; 2&#xFF0C;&#x4EFB;&#x610F;&#x547D;&#x540D;</span>
    &#x251C;&#x2500;&#x2500; global.css                 <span class="hljs-comment">// &#x7EA6;&#x5B9A;&#x7684;&#x5168;&#x5C40;&#x6837;&#x5F0F;&#x6587;&#x4EF6;&#xFF0C;&#x81EA;&#x52A8;&#x5F15;&#x5165;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x7528; global.less</span>
    &#x251C;&#x2500;&#x2500; global.js                  <span class="hljs-comment">// &#x53EF;&#x4EE5;&#x5728;&#x8FD9;&#x91CC;&#x52A0;&#x5165; polyfill</span>
&#x251C;&#x2500;&#x2500; .umirc.js                      <span class="hljs-comment">// umi &#x914D;&#x7F6E;&#xFF0C;&#x540C; config/config.js&#xFF0C;&#x4E8C;&#x9009;&#x4E00;</span>
&#x251C;&#x2500;&#x2500; .env                           <span class="hljs-comment">// &#x73AF;&#x5883;&#x53D8;&#x91CF;</span>
&#x2514;&#x2500;&#x2500; package.json
</code></pre>
<h3 id="t32.2 mock">2.2 mock <a href="#t32.2 mock"> # </a></h3>
<pre><code>&#x7EA6;&#x5B9A; mock &#x76EE;&#x5F55;&#x91CC;&#x6240;&#x6709;&#x7684; .js &#x6587;&#x4EF6;&#x4F1A;&#x88AB;&#x89E3;&#x6790;&#x4E3A; mock &#x6587;&#x4EF6;&#x3002;
&#x6BD4;&#x5982;&#xFF0C;&#x65B0;&#x5EFA; mock/users.js&#xFF0C;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;

```js
export default {
  &apos;/api/users&apos;: [&apos;a&apos;, &apos;b&apos;],
}
</code></pre><p>&#x7136;&#x540E;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x91CC;&#x8BBF;&#x95EE; <a href="http://localhost:8000/api/users">http://localhost:8000/api/users</a> &#x5C31;&#x53EF;&#x4EE5;&#x770B;&#x5230; [&apos;a&apos;, &apos;b&apos;] &#x4E86;&#x3002;</p>
<h2 id="t43. &#x542F;&#x52A8;&#x9879;&#x76EE;">3. &#x542F;&#x52A8;&#x9879;&#x76EE; <a href="#t43. &#x542F;&#x52A8;&#x9879;&#x76EE;"> # </a></h2>
<h2 id="t54. layouts">4. layouts <a href="#t54. layouts"> # </a></h2>
<h3 id="t64.1 layouts/index.js">4.1 layouts/index.js <a href="#t64.1 layouts/index.js"> # </a></h3>
<p>src/layouts/index.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component,Fragment} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">&apos;bootstrap/dist/css/bootstrap.css&apos;</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;umi/link&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Layout</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    render() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Fragment</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;navbar navbar-default&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;container-fluid&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;navbar-header&quot;</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/&quot;</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;navbar-brand&quot;</span>&gt;</span>&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
                            <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;nav navbar-nav&quot;</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;active&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/&quot;</span> &gt;</span>&#x9996;&#x9875;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/user&quot;</span> &gt;</span>&#x7528;&#x6237;&#x7BA1;&#x7406;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                                <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/profile&quot;</span>&gt;</span>&#x4E2A;&#x4EBA;&#x8BBE;&#x7F6E;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                            <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;col-md-12&quot;</span>&gt;</span>
                            {this.props.children}
                        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

            <span class="hljs-tag">&lt;/<span class="hljs-name">Fragment</span>&gt;</span></span>
        )
    }
}
</code></pre>
<h2 id="t75. &#x7528;&#x6237;&#x7BA1;&#x7406;">5. &#x7528;&#x6237;&#x7BA1;&#x7406; <a href="#t75. &#x7528;&#x6237;&#x7BA1;&#x7406;"> # </a></h2>
<h3 id="t85.1 user/_layout.js">5.1 user/_layout.js <a href="#t85.1 user/_layout.js"> # </a></h3>
<p>pages/user/_layout.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component,Fragment} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;umi/link&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    render() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;col-md-3&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;nav nav-stack&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/user/list&quot;</span>&gt;</span>&#x7528;&#x6237;&#x5217;&#x8868;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/user/add&quot;</span>&gt;</span>&#x65B0;&#x589E;&#x7528;&#x6237;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;col-md-9&quot;</span>&gt;</span>
                    {this.props.children}
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        )
    }
}
</code></pre>
<h3 id="t95.2 user/list.js">5.2 user/list.js <a href="#t95.2 user/list.js"> # </a></h3>
<p>/pages/user/list.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component,Fragment} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;umi/link&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">List</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    render() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;list-group&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;list-group-item&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/user/detail/1&quot;</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span></span>
        )
    }
}
</code></pre>
<h3 id="t105.3 pages/user/add.js">5.3 pages/user/add.js <a href="#t105.3 pages/user/add.js"> # </a></h3>
<p>pages/user/add.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component,Fragment} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Add</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    render() {
        <span class="hljs-keyword">return</span> (
            &lt;form className=&quot;form-horizontal&quot;&gt;
                &lt;div className=&quot;form-group&quot;&gt;
                    &lt;label className=&quot;control-label col-md-2&quot;&gt;&#x7528;&#x6237;&#x540D;&lt;/label&gt;
                    &lt;div className=&quot;col-md-10&quot;&gt;
                       &lt;input className=&quot;form-control&quot; /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div className=&quot;form-group&quot;&gt;
                    &lt;div className=&quot;col-md-10 col-offset-2&quot;&gt;
                       &lt;input type=&quot;submit&quot; className=&quot;btn btn-primary&quot;/&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/form&gt;
        )
    }
}
</code></pre>
<h3 id="t115.3 detail/$id.js">5.3 detail/$id.js <a href="#t115.3 detail/$id.js"> # </a></h3>
<p>pages/user/detail/$id.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component,Fragment} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">List</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    render() {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.props);
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;table table-bordered&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x5B57;&#x6BB5;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x503C;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x5F20;&#x4E09;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span></span>
        )
    }
}
</code></pre>
<h2 id="t126. &#x6743;&#x9650;&#x8DEF;&#x7531;">6. &#x6743;&#x9650;&#x8DEF;&#x7531; <a href="#t126. &#x6743;&#x9650;&#x8DEF;&#x7531;"> # </a></h2>
<h3 id="t136.1  profile.js">6.1  profile.js <a href="#t136.1  profile.js"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">/**
 * title: Profile Page
 * Routes:
 *   - ./PrivateRoute.js
 */</span>
</code></pre>
<h3 id="t146.2 routes/PrivateRoute.js">6.2 routes/PrivateRoute.js <a href="#t146.2 routes/PrivateRoute.js"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { Route ,Redirect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react-router-dom&apos;</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> (args) =&gt; {
  <span class="hljs-keyword">const</span> { render, ...rest } = args;
  <span class="hljs-keyword">return</span> &lt;Route
    {...rest}
    render={props =&gt; localStorage.getItem(&apos;login&apos;)?render(props):&lt;Redirect to=&quot;/&quot;/&gt;
    }
  /&gt;;
}
</code></pre>
<h2 id="t157. react&#x52A8;&#x753B;">7. react&#x52A8;&#x753B; <a href="#t157. react&#x52A8;&#x753B;"> # </a></h2>
<pre><code class="lang-js">npm install react-transition-group --save
</code></pre>
<h3 id="t167.1 src/pages/user/_layout.js">7.1 src/pages/user/_layout.js <a href="#t167.1 src/pages/user/_layout.js"> # </a></h3>
<p>src/pages/user/_layout.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React,{Component,Fragment} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> Link <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;umi/link&apos;</span>;
<span class="hljs-keyword">import</span> { TransitionGroup, CSSTransition } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;react-transition-group&quot;</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    render() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;col-md-3&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;nav nav-stack&quot;</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/user/list&quot;</span>&gt;</span>&#x7528;&#x6237;&#x5217;&#x8868;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">Link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/user/add&quot;</span>&gt;</span>&#x65B0;&#x589E;&#x7528;&#x6237;<span class="hljs-tag">&lt;/<span class="hljs-name">Link</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">&quot;col-md-9&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">TransitionGroup</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">CSSTransition</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{this.props.location.pathname}</span> <span class="hljs-attr">classNames</span>=<span class="hljs-string">&quot;fade&quot;</span> <span class="hljs-attr">timeout</span>=<span class="hljs-string">{300}</span>&gt;</span>
                        {this.props.children}
                        <span class="hljs-tag">&lt;/<span class="hljs-name">CSSTransition</span>&gt;</span>
                    <span class="hljs-tag">&lt;/<span class="hljs-name">TransitionGroup</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        )
    }
}
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.fade-enter</span> {
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">1</span>;
}

<span class="hljs-selector-class">.fade-enter</span><span class="hljs-selector-class">.fade-enter-active</span> {
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">transition</span>: opacity <span class="hljs-number">250ms</span> ease-in;
}
</code></pre>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
